#include <iostream>
using namespace std;

class Solution
{
public:
    bool isHappy(int n)
    {
        int low = get_num(n);
        int fast = get_num(get_num(n));

        while (low != fast)
        {
            low = get_num(low);
            fast = get_num(get_num(fast));
        }

        return fast == 1;
    }

    int get_num(int n)
    {
        int ret = 0;
        while (n)
        {
            ret += (n % 10) * (n % 10);
            n /= 10;
        }

        return ret;
    }
};


int main()
{
    int n = 0;
    cin >> n;
    Solution s;
    cout << s.isHappy(n);
    return 0;
}